﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace HotelManagement
{
    public partial class ReserveSerach : Form
    {

        public int Rs_ID;
        public int rm_id;
        public int c_id;
        public int f_id;
        SqlConnection Cnn = new SqlConnection(Globals.DBConnection());
        DataSet ds = new DataSet();
        SqlDataAdapter da;
        SqlDataReader dr;


        public ReserveSerach()
        {
            InitializeComponent();
        }

        private void ReserveSerach_Load(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select rs_id as [شماره نامه رزرو],c_fname as[نام],c_lname as[نام خانوادگی],rs_sdate as[تاریخ شروع],rs_edate as[تاریخ پایان],rs_persons as[تعداد همراهان],rm_number as[شماره اتاق],rs_tprice as[هزینه رزرو اتاق],c_id,rm_id,f_id from Reserve,Customer,Room,Factor Where  rm_id=rs_rm_id AND rs_c_id=c_id AND f_rs_id =rs_id", Cnn);

            da.Fill(ds);
            dGViewReserveSearch.DataSource = ds.Tables[0];
            dGViewReserveSearch.Columns[8].Visible = false;
            dGViewReserveSearch.Columns[9].Visible = false;
            dGViewReserveSearch.Columns[10].Visible = false;
        }

        private void RsIdSearchTxt_TextChanged(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select rs_id as [شماره نامه رزرو],c_fname as[نام],c_lname as[نام خانوادگی],rs_sdate as[تاریخ شروع],rs_edate as[تاریخ پایان],rs_persons as[تعداد همراهان],rm_number as[شماره اتاق],rs_tprice as[هزینه رزرو اتاق],c_id,rm_id,f_id from Reserve,Customer,Room,Factor Where (rs_id LIKE @rs_id + N'%' OR @rs_id=N'') AND (c_fname LIKE @fname + N'%' OR @fname=N'') AND (c_lname LIKE @lname + N'%' OR @lname=N'') AND (rm_number LIKE @number +N'%' OR @number=N'') AND rm_id=rs_rm_id AND rs_c_id=c_id AND f_rs_id =rs_id", Cnn);
          
            da.SelectCommand.Parameters.AddWithValue("@rs_id",RsIdSearchTxt.Text.Trim());
            da.SelectCommand.Parameters.AddWithValue("@fname",fNameSearchTxt.Text.Trim());
            da.SelectCommand.Parameters.AddWithValue("@lname",LnameSearchTxt.Text.Trim());
            da.SelectCommand.Parameters.AddWithValue("@number",RoomNumberSearchTxt.Text.Trim());

            ds.Clear();
            da.Fill(ds);
            dGViewReserveSearch.DataSource = ds.Tables[0];
        }

        private void dGViewReserveSearch_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            Rs_ID = (int)dGViewReserveSearch.CurrentRow.Cells[0].Value;
            c_id = (int)dGViewReserveSearch.CurrentRow.Cells[8].Value;
            rm_id = (int)dGViewReserveSearch.CurrentRow.Cells[9].Value;
            f_id = (int)dGViewReserveSearch.CurrentRow.Cells[10].Value;

            this.Close();
        }

    }
}
